package com.xidian.zhiancloud.controller.myyb;

import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.SysJobTable;
import com.xidian.zhiancloud.model.SysOrganizationAbandon;
import com.xidian.zhiancloud.service.myyb.IJobTableService;
import com.xidian.zhiancloud.service.myyb.OrganizationAbandonService;
import com.xidian.zhiancloud.service.myyb.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统设置-岗位管理
 *
 */
@RestController
@RequestMapping("/jobTable")
public class JobTableController {

    private final static Logger logger = LoggerFactory.
            getLogger(JobTableController.class);

    @Autowired
    private IJobTableService jobTableService;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private OrganizationAbandonService organizationService;

    /**
     * 岗位管理列表
     * @param positionName 岗位名称
     * @return 返回 ResultDTO 对象
     */
    @GetMapping("/jobTable_list")
    public ResultDTO<List<SysJobTable>> selectJobTableList(@RequestParam("positionName") String positionName) {
        String jobTableStatus = "0";
        Map<String, Object> mapResult = new HashMap<String, Object>();
        mapResult.put("jobTableStatus", jobTableStatus);
        List<SysJobTable> jobTableList = jobTableService.selectJobTableList(mapResult);
        int post = 0 ;
        SysOrganizationAbandon organization = new SysOrganizationAbandon();
        for (SysJobTable jobTable : jobTableList){
            post = userService.selectByUserPost(jobTable.getPositionName());
            organization = organizationService.getById(
                    jobTable.getOrganizationId());
        }
        return ResultDTO.successOf(jobTableService.selectJobTableList(mapResult),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除岗位
     *  @param id 岗位ID
     * @return 返回 ResultDTO 对象
     */
    @GetMapping("/deleteJobTable")
    public ResultDTO<Integer> deleteJobTable(@RequestParam("id") Long id){
        jobTableService.deleteJobTableById(id);
        return ResultDTO.successOf(jobTableService.deleteJobTableById(id),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 编辑
     * @param jobtable 编辑岗位信息数据
     * @return 返回 ResultDTO 对象
     */
    @PatchMapping("/patchById")
    public ResultDTO<Boolean> patchById(SysJobTable jobtable) {
        jobTableService.patchById(jobtable);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 添加
     * @param jobtable 岗位信息数据
     * @return 返回 ResultDTO 对象
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(SysJobTable jobtable) {
        jobTableService.add(jobtable);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }


}
